package com.xf.system.common.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xf.system.common.mapper.UserDeptMapper;
import com.xf.system.common.model.UserDept;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xiefengf
 */
@Slf4j
@Service
public class UserDeptService extends ServiceImpl<UserDeptMapper, UserDept> {

    @Resource
    private UserDeptMapper userDeptMapper;

    /**
     * 删除用户与部门关联
     * @param userId 用户id
     * @return 执行结果
     */
    public Boolean deleteUserDeptByUid(Long userId) {
        LambdaQueryWrapper<UserDept> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserDept::getUserId,userId);
        return remove(wrapper);
    }

    /**
     * 删除用户与部门关联
     * @param userIdList 用户id集合
     * @return 执行结果
     */
    public Boolean deleteUserDeptByUidList(List<Long> userIdList) {
        LambdaQueryWrapper<UserDept> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(UserDept::getUserId,userIdList);
        return remove(wrapper);
    }

    /**
     * 根据部门id,查询对应的所有用户id
     *
     * @param deptId 部门主键id
     * @return 用户id主键集合
     */
    public List<Long> selectUserIdByDeptId(Long deptId) {
        return userDeptMapper.selectUserIdByDeptId(deptId);
    }


}
